#include <iostream>
#include <string>
#include <cstdlib>
#include <ctime>
#include <cmath>


int check2(int pass){
        long seed = std::pow(pass, 2);
        long section = seed^2;
        return section;
}

int check0(long pass){
	short i = 0;
	while (pass/10 >= 10){
		i++;
		pass = pass/10;
	}
        return i+2;

}
int check1(long pass, int len){
	if (len % 3 != 0) return 0;
	for (int i = 0; i<3;i++){
		long power = std::pow(10,((len/3))*(i+1));

		long remainder = pass % power;

		if(remainder%3 !=0) return 0;
	}
	return 1;
}
int main() {

	long password = 0;
	std::cout << "Введите ключ: ";
	std::cin >> password;
	long  a = check2(password) + check0(password);
	if (check2(password)==0){
		std::cout << "Ключ не соотвествует требованиям" << std::endl;
	}

	if (check1(password, check0(password)) == 1 && check2(password)!=a-1){
		std::cout << "Ключ принят" << std::endl;
	}
	else{
		std::cout << "Ключ не принят" << std::endl;
	}

	return 0;
}


